﻿using System;
using System.Collections.ObjectModel;
using University.Workshop.Business;

namespace University.Workshop.Presenters.Square.Search
{
    public class PresenterSearchSquare
    {
        private ISearchSquareView view;

        public PresenterSearchSquare(ISearchSquareView View)
        {
            view = View;
        }

        public void SearchKardex()
        {
            try
            {
                var k = new Model.Square {SquareId = view.SquareIdRelative};
                view.SquareFinded = ManagerSquare.GetSquareByRelativeIdAndState(k, view.StateSquare);
            }
            catch (Exception ex)
            {
                view.SquareFinded = null;
                view.NotifyErrorMessage(ex.Message);
            }
        }


        private void ClenSearch()
        {
            view.SquareIdRelative = string.Empty;
            view.SquareFinded = new Collection<Model.Square>();
        }

        public void EnableSquare()
        {
            try
            {
                ManagerSquare.EnableSquare(view.SquareSeleted);
                ClenSearch();
                view.NotifySystemMessage("El Manzano fue habilitado exitosamente");
            }
            catch (Exception ex)
            {
                view.NotifyErrorMessage(ex.Message);
            }
        }

        public void DisableSquare()
        {
            try
            {
                ManagerSquare.DisableSquare(view.SquareSeleted);
                ClenSearch();
                view.NotifySystemMessage("El Manzano fue inhabilitado exitosamente");
            }
            catch(Exception ex)
            {
                view.NotifyErrorMessage(ex.Message);
            }
        }
    }
}
